package com.hinnotek.amoeba.viewmodels


import androidx.lifecycle.viewModelScope
import com.hinnotek.amoeba.base.BaseBean
import com.hinnotek.amoeba.bean.old.CompanyContractByIdBean
import com.hinnotek.amoeba.bean.old.CompanyContractListBean
import com.hinnotek.amoeba.bean.old.PBDetailBean
import com.hinnotek.amoeba.bean.old.PBListBean
import com.hinnotek.amoeba.repo.ContractRepo
import com.lee.common.base.BaseViewModel
import com.lee.common.network.net.StateLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import okhttp3.RequestBody
import javax.inject.Inject

@HiltViewModel
class ContractViewModel @Inject constructor(private val contractRepo: ContractRepo) :
    BaseViewModel() {

    val companyContractByIdData = StateLiveData<CompanyContractByIdBean>()
    val pBListDate = StateLiveData<MutableList<PBListBean>>()
    val companyContractListData = StateLiveData<MutableList<CompanyContractListBean>>()
    val pBDetailData = StateLiveData<PBDetailBean>()
    val baseBean = StateLiveData<BaseBean>()
    val baseBean2 = StateLiveData<BaseBean>()

    fun getCompanyContractByIdData(companyContractId: Int):StateLiveData<CompanyContractByIdBean> {
        viewModelScope.launch {
            contractRepo.getCompanyContractById(companyContractId, companyContractByIdData)
        }
        return companyContractByIdData
    }

    fun getCompanyContractPageByUnComplete(pageNo: Int,pageSize: Int,):StateLiveData<MutableList<PBListBean>> {
        viewModelScope.launch {
            contractRepo.getCompanyContractPageByUnComplete(pageNo,pageSize, pBListDate)
        }
        return pBListDate
    }

    fun getCompanyContractPage(requestBody: RequestBody): StateLiveData<MutableList<CompanyContractListBean>>{
        viewModelScope.launch {
            contractRepo.getCompanyContractPage(requestBody, companyContractListData)
        }
        return companyContractListData
    }

    val baseData = StateLiveData<BaseBean>()

    fun addCompanyContract(requestBody: RequestBody):StateLiveData<BaseBean> {
        viewModelScope.launch {
            contractRepo.addCompanyContract(requestBody, baseData)
        }
        return baseData
    }

    fun getCompanyContractByIdForUnComplete(companyContractId: Int) :StateLiveData<PBDetailBean>{
        viewModelScope.launch {
            contractRepo.getCompanyContractByIdForUnComplete(companyContractId, pBDetailData)
        }
        return pBDetailData
    }

    fun addCompanyContractBack(companyContractId: Int, backMoney: String): StateLiveData<BaseBean> {
        viewModelScope.launch {
            contractRepo.addCompanyContractBack(companyContractId,backMoney, baseBean)
        }
        return baseBean
    }

    fun updateCompanyContractBackStateComplete(companyContractId: Int): StateLiveData<BaseBean> {
        viewModelScope.launch {
            contractRepo.updateCompanyContractBackStateComplete(companyContractId, baseBean2)
        }
        return baseBean2
    }


}